package com.erp.app.admin.systemMenu.web;

//JRE Classes
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.erp.app.admin.systemMenu.beans.SystemMenuGroupVO;
import com.erp.app.admin.systemMenu.dao.SystemMenuGroupSrchCriteria;
import com.erp.app.admin.systemMenu.ejb.SystemMenuGroupPK;
import com.erp.app.common.ProjectConstants;
import com.erp.app.util.web.WebUtil;
import com.erp.framework.controller.action.SimpleSearchStyleAction;
import com.erp.framework.controller.form.SimpleSearchStyleForm;
import com.erp.framework.model.pk.SimpleBasePk;

public class SystemMenuSearchAction extends SimpleSearchStyleAction {

    protected String getFunctionId() {
        // struts-config xxxxx.do
        return "systemMenuSearch.do";
    }

    protected Class getMasterFormClass() {
        // the corresponding form class
        return SystemMenuSearchForm.class;
    }

    protected Class getMasterVOClass() {
        // corresponding master vo class
        return SystemMenuGroupVO.class;
    }

    protected Class getSearchCriteriaClass() {
        // corresponding searching criteria class
        return com.erp.app.admin.systemMenu.dao.SystemMenuGroupSrchCriteria.class;
    }

    protected String getModuleName(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response) {
        return ProjectConstants.MOD_SYSTEM_MENU_SEARCH;
    }

    protected SimpleBasePk getPk(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {
        SystemMenuSearchForm form = (SystemMenuSearchForm) formIn;
        HttpSession session = request.getSession(false);

        /*
         * String appropriateCompany =
         * WebUtil.getAppropriateCompanyCode(session,
         * Constants.SP_EDIT_OTHER_COMPANY); MenuGroupPK pk = new
         * MenuGroupPK(appropriateCompany, form.getGroupId(),form.getMenuId());
         */

        SystemMenuGroupPK pk = new SystemMenuGroupPK(form.getEditCompanyCode(), form.getEditGroupId(), form.getEditMenuId());

        return pk;
    }

    protected void setOtherCriteria(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors, Object criteria) {
        HttpSession session = request.getSession(false);

        String isShare = WebUtil.getSysParamVal(session, ProjectConstants.SP_SHARE_SYSTEM_MENU);

        // System.out.println("$$$$$$$$ setOtherCriteria's companyCode = " +
        // WebUtil.getAppropriateCompanyCode(session, null));

        if (!ProjectConstants.GENERIC_YES.equals(isShare)) {
            String companyCode = WebUtil.getAppropriateCompanyCode(session, null);
            ((SystemMenuGroupSrchCriteria) criteria).setSrchCompanyCode(companyCode);
        }
    }

    public ActionForward handlePageEvent(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
            HttpServletResponse response, ActionErrors errors) {
        return null;
    }

    protected void initAction(ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) {

    }

    protected String getSessionMasterDelegate() {
        return "MASTER_DELEGATE";
    }

    protected String getMasterFormSessionName() {
        return "systemMenuSearchForm";
    }

    protected String getSessionSimpleSearchStatus() {
        return ProjectConstants.SESSION_SIMPLE_SEARCH_STATUS;
    }

    protected String getSessionSimpleMaintStatus() {
        return ProjectConstants.SESSION_SIMPLE_MAINT_STATUS;
    }

    protected String getSessionSimpleMaintPk() {
        return ProjectConstants.SESSION_SIMPLE_MAINT_PK;
    }

    protected String getSessionSimpleMaintInitModel() {
        return ProjectConstants.SESSION_SIMPLE_MAINT_INIT_MODEL;
    }

    protected String getSessionSimpleMaintEditType() {
        return ProjectConstants.SESSION_SIMPLE_MAINT_EDIT_TYPE;
    }

    protected boolean getLoadOnEnter() {
        return true;
    }

    protected boolean getResetOnEnter() {
        return false;
    }

    protected String getSessionReset() {
        return ProjectConstants.SESSION_SIMPLE_SEARCH_RESET;
    }

    protected void setFormType(ActionMapping mapping, ActionForm formIn, HttpServletRequest request,
        HttpServletResponse response, ActionErrors errors){
        SimpleSearchStyleForm form = (SimpleSearchStyleForm)formIn;
        form.setFormType(ProjectConstants.FORM_TYPE_SEARCH);
    }
    
}
